'''
Created on 31/10/2011

@author: Mateo
'''

class Block(object):
    '''
    classdocs
    '''


    def __init__(self, start, end):
        '''
        Constructor
        '''
        self.start = start
        self.end = end
        
        
    def blockSize(self):
        
        return self.end - self.start + 1
    
        
    def calculateLarge(self):
        
        return self.end - self.start
    
    def setEnd(self, num):
        
        self.end = num
    
    def reduceBlock(self, sizeInstructions):
        
        usedBlock = Block(self.start, sizeInstructions - 1)
        self.start += sizeInstructions
        
        return usedBlock    
    
    def reSize(self, block):
        #AGRANDA EL BLOQUE
        if self.imFirst(block):
            self.end = block.getEnd()
        else:
            self.start = block.getStart()
            
        return self
        
    def continuousBlocks(self, block):
        
        return self.start == block.getEnd() + 1 or self.end + 1 == block.getStart()
    
    def getStart(self):
        
        return self.start
    
    def getEnd(self):
        
        return self.end
            
    def imFirst(self, aBlock):
        
        return self.end < aBlock.getStart()
    
    def registerAllocation(self):
        
        actual = self.start
        self.start = self.start - 1
        
        return actual
        
        
                
        